import java.util.Arrays;

public class J2410161 {
    public static int binarySearch(int[] array,int key) {
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(array[mid] < key){
                left = mid + 1;
            } else if (array[mid] > key) {
                right = mid - 1;
            }else{
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3,13,4,15};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
        System.out.println(binarySearch(array,15));
    }

}
